package com.hihiwjc.app.zzmh.adapters.home;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.hihiwjc.app.zzmh.R;
import com.hihiwjc.app.zzmh.entities.home.Recommend;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * <br/>Created by hihiwjc on 2015/10/29 0029
 * <br/>Author:hihiwjc
 * <br/>Email:hihiwjc@live.com
 */

public class RecommendListItemType1GridAdapter extends BaseAdapter {
    private List<Recommend.ListsEntity.ThemeListEntity> mDatas;
    private Context mContext;

    public RecommendListItemType1GridAdapter(Context mContext, List<Recommend.ListsEntity.ThemeListEntity> mDatas) {
        this.mContext = mContext;
        this.mDatas = mDatas;
    }

    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public Recommend.ListsEntity.ThemeListEntity getItem(int position) {
        return mDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view;
        ViewHolder viewHolder;
        Recommend.ListsEntity.ThemeListEntity item = getItem(position);
        if (convertView == null) {
            view = LayoutInflater.from(mContext).inflate(R.layout.item_gv_item1_lv_fragment_main_recommend_grid, parent, false);
            viewHolder = new ViewHolder();
            viewHolder.iv_item_gv_item1_lv_fragment_main_recommend_grid = (ImageView) view.findViewById(R.id.iv1_item_gv_item1_lv_fragment_main_recommend_grid);
            viewHolder.tv_item_gv_item1_lv_fragment_main_recommend_grid = (TextView) view.findViewById(R.id.tv1_item_gv_item1_lv_fragment_main_recommend_grid);
            view.setTag(viewHolder);
        } else {
            view = convertView;
            viewHolder = (ViewHolder) view.getTag();
        }
        viewHolder.tv_item_gv_item1_lv_fragment_main_recommend_grid.setText(item.getName());
        Picasso.with(mContext).load(item.getCover()).placeholder(R.mipmap.ic_launcher).into(viewHolder.iv_item_gv_item1_lv_fragment_main_recommend_grid);
        return view;
    }

    private static class ViewHolder {
        public TextView tv_item_gv_item1_lv_fragment_main_recommend_grid;
        public ImageView iv_item_gv_item1_lv_fragment_main_recommend_grid;
    }
}
